// @flow

const TRIGGLE_SIDEBAR = 'TRIGGLE_SIDEBAR'

type Action = {
  type: string,
  id: string
}

export const toggleSidebar = (id: string) => {
  return {
    type: TRIGGLE_SIDEBAR,
    id
  }
}

const ACTION_HANDLERS = {
  [TRIGGLE_SIDEBAR]: (state, { id }: Action) => Object.assign({}, state, {
    [id]: !state[id]
  })
}

type State = Object

const initialState = {
  deviceFile: true,
  menuSidebar: true
}

export default function sidebarReducer (state: State = initialState, action: Action) {
  const handler = ACTION_HANDLERS[action.type]

  return handler ? handler(state, action) : state
}
